package com.warmlight.voicepacket.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.github.siyamed.shapeimageview.CircularImageView;
import com.github.siyamed.shapeimageview.RoundedImageView;
import com.warmlight.voicepacket.R;
import com.warmlight.voicepacket.activity.VideoDetailsActivity;
import com.warmlight.voicepacket.bean.cdetails.CDetailsListBean;
import com.warmlight.voicepacket.bean.comm.RecommPictureBean;
import com.warmlight.voicepacket.bean.comm.UserBean;
import com.warmlight.voicepacket.ui.imlm.GoodListenerTeaseActivity;
import com.warmlight.voicepacket.ui.user.usercenter.LookUserCenterActivity;
import com.warmlight.voicepacket.utils.JSONUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MyMessageAdapter extends RecyclerView.Adapter<MyMessageAdapter.HashViewHolder> {


    private final RequestOptions options;

    public MyMessageAdapter(Context context) {
        options = new RequestOptions();
        options.placeholder(R.drawable.icon_roud_placeholder);
        this.mContext = context;
        mItems = new ArrayList<>();
    }

    protected Context mContext;
    private List<Map<String,String>> mItems;


//    @Override
//    public HashViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
//    }

//    @Override
//    public void onBindViewHolder(HashViewHolder hashViewHolder, int position) {
//
//    }

    @Override
    public int getItemCount() {
        if(mItems == null)
            return 0;
        return mItems.size();
    }

    public Map<String,String> getItem(int position) {
        if(mItems == null)
            return null;
        if(position < mItems.size())
            return mItems.get(position);
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setItems(List<Map<String,String>> items){
        if (this.mItems != null){
            this.mItems.clear();
            this.mItems.addAll(items);
        }
//        this.mItems = items;
        notifyDataSetChanged();
    }

    public void addItems(List<Map<String,String>> items) {
        if(mItems != null) {
            this.mItems.addAll(items);
            notifyDataSetChanged();
        }
    }

    public List<Map<String,String>> getItems(){
        return mItems;
    }

    public void removeItem(Map<String,String> t){
        int index = mItems.indexOf(t);
        if(index >= 0) {
            mItems.remove(t);
            notifyItemRemoved(index);
        }
    }

    public void addItem(Map<String,String> t){
        if(!mItems.contains(t)) {
            mItems.add(t);
            notifyItemInserted(getItemCount() - 1);
        }
    }

    /**
     * 消息类型：0评论我的帖子
     * 1评论我的评论
     * 2在我的帖子中回复了别人
     * 3赞了我的帖子
     * 4赞了我的评论
     * 5其它
     * 6系统可点击消息
     * 7对我的音频点赞
     * @param position
     * @return
     */
    @Override
    public int getItemViewType(int position) {
        Map<String,String> item = getItem(position);
        String type = item.get("type");
        if (TextUtils.equals("7",type)) {
            return 0;
        }else if (TextUtils.equals("0",type)){
            return 1;
        }else if (TextUtils.equals("1",type)){
            return 2;
        }else if (TextUtils.equals("2",type)){
            return 3;
        }else if (TextUtils.equals("3",type)){
            return 4;
        }else if (TextUtils.equals("4",type)){
            return 5;
        }else if (TextUtils.equals("5",type)){
            return 6;
        }else if (TextUtils.equals("6",type)){
            return 7;
        }

        return super.getItemViewType(position);
    }

    @Override
    public HashViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        HashViewHolder holder = null;
        if (viewType == 0) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_mymessage, parent, false);
            HashViewHolder viewHolder = new HashViewHolder(view);
            viewHolder.putView(R.id.ci_head);
            viewHolder.putView(R.id.tv_nickname);
            viewHolder.putView(R.id.tv_content);
            viewHolder.putView(R.id.tv_time);
            holder = viewHolder;
        }else{
            View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_my_message,parent,false);
            HashViewHolder holder1 = new HashViewHolder(view);
            holder1.putView(R.id.ci_head_img);
            holder1.putView(R.id.tv_nickname);
            holder1.putView(R.id.tv_zan);
            holder1.putView(R.id.tv_ping);
            holder1.putView(R.id.tv_time);
            holder1.putView(R.id.rl_tv_iv);
            holder1.putView(R.id.iv_img);
            holder1.putView(R.id.tv_msg);
            holder = holder1;
        }

        return holder;


    }


    /**
     * {

     "data": {
     "has_more": 0,
     "list": [{
     "id": "44",
     "uid": "100016",
     "content": "这是一个系统消息内容",
     "type": "6",
     "jump_page": "1",
     "pic": "https:\/\/nuanguang-img.oss-cn-shanghai.aliyuncs.com\/post\/721200013e067d76d04a~998x519.webp",
     "related_id": null,
     "send_uid": "4",
     "add_time": "1532087732",
     "read_time": "0",
     "update_time": "2018-08-28 20:08:50",
     "author": {
     "uid": "4",
     "nickname": "太阳",
     "avator": "",
     "sex": "1",
     "sign": ""
     },
     "datetime": "07-20 19:55"
     }]
     * @param holder
     * @param position
     * /**
     * 消息类型：0评论我的帖子
     * 1评论我的评论
     * 2在我的帖子中回复了别人
     * 3赞了我的帖子
     * 4赞了我的评论
     * 5其它
     * 6系统可点击消息
     * 7对我的音频点赞
     * @param position
     * @return
     * /**
     *  {
    "id":"847",
    "uid":"1003",
    "content":"回复了你的评论",
    "type":"1",
    "jump_page":"2",
    "pic":null,
    "related_id":"88322",
    "send_uid":"162824",
    "add_time":"1536840554",
    "read_time":"0",
    "update_time":"2018-09-13 20:09:14",
    "text":null,
    "author":{
    "uid":"162824",
    "nickname":"哈哈57",
    "avator":"http://wanpi-img.oss-cn-shanghai.aliyuncs.com/wanpi/162824/avator/avator1536220391485.png",
    "sex":"1",
    "sign":""
    },
    "datetime":"32分钟前",
    "post_res":{
    "id":"2409",
    "content":"我可能养了只假狗",
    "video":{
    "w":320,
    "h":560,
    "u":"https://nuanguang-img.oss-cn-shanghai.aliyuncs.com/audio/v0204c0f0000bdodpng7q8i9jakb47hg.mp4",
    "duration":15,
    "cover_img":{
    "w":320,
    "h":560,
    "u":"https://nuanguang-img.oss-cn-shanghai.aliyuncs.com/post/a5310007ad2cc1066f97~320x560_q80.webp",
    "is_gif":false
    }
    },
    "pics":[

    ],
    "category":"2",
    "status":"1"
    },
    "comment_res":{
    "id":"88314",
    "pics":[

    ],
    "content":"急急急",
    "status":"2",
    "post_id":"2409",
    "reply_id":"0"
    },
    "reply_res":{
    "id":"88322",
    "pics":[

    ],
    "content":"历经磨难",
    "status":"2",
    "post_id":"2409",
    "reply_id":"88314"
    }
    },
     *
     */
    @Override
    public void onBindViewHolder(HashViewHolder holder, int position) {
        int itemViewType = holder.getItemViewType();
        if (itemViewType == 0) {//点赞音频
            Map<String, String> item = getItem(position);
            String id = item.get("id");
            String uid = item.get("uid");
            String content = item.get("content");
            final String type = item.get("type");
            final String jump_page = item.get("jump_page");//消息跳转页面：1帖子2评论3发布的音频
            String pic = item.get("pic");
            String related_id = item.get("related_id");//跳转到对应的id
            String send_uid = item.get("send_uid");
            String add_time = item.get("add_time");
            String read_time = item.get("read_time");
            String update_time = item.get("update_time");
            String author = item.get("author");
            String datetime = item.get("datetime");

            String a_uid = "";
            String a_nickname = "";
            String a_avator = "";
            String a_sex = "";
            String a_sign = "";
            if (!TextUtils.isEmpty(author)) {
                ArrayList<Map<String, String>> authors = JSONUtils.getListMapByJson(author);
                if (authors.size() > 0) {
                    Map<String, String> map = authors.get(0);
                    a_uid = map.get("uid");
                    a_nickname = map.get("nickname");
                    a_avator = map.get("avator");
                    a_sex = map.get("sex");
                    a_sign = map.get("sign");
                }
            }

            CircularImageView ci_head = (CircularImageView) holder.findView(R.id.ci_head);
            TextView tv_nickname = (TextView) holder.findView(R.id.tv_nickname);
            TextView tv_content = (TextView) holder.findView(R.id.tv_content);
            TextView tv_time = (TextView) holder.findView(R.id.tv_time);


            if (options != null) {
                Glide.with(mContext).asBitmap().load(a_avator).apply(options)
                        .into(ci_head);
            }

            final String finalA_uid = a_uid;
            ci_head.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid", finalA_uid);
                    intent.putExtra("type","cover");
                    mContext.startActivity(intent);
                }
            });

            tv_nickname.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid", finalA_uid);
                    intent.putExtra("type","cover");
                    mContext.startActivity(intent);
                }
            });

            tv_nickname.setText(a_nickname);
            tv_content.setText(content);
            tv_time.setText(datetime);

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (TextUtils.equals("7", type)) {
                        //1帖子2评论3发布的音频
                        if (TextUtils.equals("1", jump_page)) {

                        } else if (TextUtils.equals("2", jump_page)) {

                        } else if (TextUtils.equals("3", jump_page)) {
                            //跳转到我的音频
                            Intent intent = new Intent(mContext, GoodListenerTeaseActivity.class);
                            intent.putExtra("jump_page", "3");
                            mContext.startActivity(intent);
                        }
                    }
                }
            });
//        }else if (itemViewType == 1){
        } else {
            final Map<String,String> item = getItem(position);
            CircularImageView ci_head_img = (CircularImageView) holder.findView(R.id.ci_head_img);
            TextView tv_nickname = (TextView) holder.findView(R.id.tv_nickname);
            TextView tv_zan = (TextView) holder.findView(R.id.tv_zan);
            TextView tv_ping = (TextView) holder.findView(R.id.tv_ping);
            TextView tv_time = (TextView) holder.findView(R.id.tv_time);
            RelativeLayout rl_tv_iv = (RelativeLayout) holder.findView(R.id.rl_tv_iv);
            RoundedImageView iv_img = (RoundedImageView) holder.findView(R.id.iv_img);
            TextView tv_msg = (TextView) holder.findView(R.id.tv_msg);
            //数据
            String id = item.get("id");//消息id
            final String uid = item.get("uid");//接收者UID
            String content = item.get("content");//消息内容
            /**
             * * 消息类型：0评论我的帖子
             * 1评论我的评论
             * 2在我的帖子中回复了别人
             * 3赞了我的帖子
             * 4赞了我的评论
             * 5其它
             * 6系统可点击消息
             * 7对我的音频点赞
             */
            final String type = item.get("type");//消息类型：0评论我的帖子1评论我的评论2在我的帖子中回复了别人3赞了我的帖子4赞了我的评论5其它6系统可点击消息7对我的音频点赞
            String jump_page = item.get("jump_page");//消息跳转页面：1帖子2评论3发布的音频
            String pic = item.get("pic");//对应的图片，空为无图片，否则为图片地址
            String related_id = item.get("related_id");//跳转到对应的id
            String send_uid = item.get("send_uid");//发送者的uid
            String add_time = item.get("add_time");//添加时间戳
            String read_time = item.get("read_time");//读取时间
            String update_time = item.get("update_time");//更新时间
            String author = item.get("author");//发送者的用户信息
            final String datetime = item.get("datetime");//发送时间，前端显示用
            String a_uid = "";
            String a_nickname = "";
            String a_avator = "";
            String a_sex = "";
            String a_sign = "";
            //对我评论的人的信息
            if (!TextUtils.isEmpty(author)) {
                ArrayList<Map<String, String>> authors = JSONUtils.getListMapByJson(author);
                if (authors.size() > 0) {
                    Map<String, String> map = authors.get(0);
                    a_uid = map.get("uid");
                    a_nickname = map.get("nickname");
                    a_avator = map.get("avator");
                    a_sex = map.get("sex");
                    a_sign = map.get("sign");
                }
            }

            /**
             * "comment_res":{
             "id":"88314",
             "pics":[

             ],
             "content":"急急急",
             "status":"2",
             "post_id":"2409",
             "reply_id":"0"
             }
             */

            //帖子的评论
            final String comment_res = item.get("comment_res");
            String comment_res_id = "";
            String coment_res_pics = "";
            String coment_res_content = "";
            String coment_res_post_id = "";
            if (!TextUtils.isEmpty(comment_res)){
                ArrayList<Map<String, String>> comment_res_list = JSONUtils.getListMapByJson(comment_res);
                if (comment_res_list.size()>0){
                    Map<String, String> map = comment_res_list.get(0);
                    comment_res_id = map.get("id");
                    coment_res_pics = map.get("pics");
                    coment_res_content = map.get("content");
                    coment_res_post_id = map.get("post_id");
                }
            }


            //别人回复你的信息
            final String reply_res = item.get("reply_res");
            String reply_res_content="";//别人回复我的信息
            String reply_res_id = "";//回复的回复的id
            if (!TextUtils.isEmpty(reply_res)){
                ArrayList<Map<String, String>> reply_ress = JSONUtils.getListMapByJson(reply_res);
                if (reply_ress.size()>0){
                    Map<String, String> map = reply_ress.get(0);
                    reply_res_id = map.get("id");
                    reply_res_content = map.get("content");
                    String status = map.get("status");
                }
            }
            //当前帖子的信息，展示右侧的图片或者文字
            String post_res = item.get("post_res");
            String post_res_content = "";//右侧文字 没有图片就展示文字
            String pic_right = "";//右侧图片
            String post_res_id = "";//帖子的id
            String post_res_category = "";
            String videoW = "";
            String videoH = "";
            if (!TextUtils.isEmpty(post_res)){
                ArrayList<Map<String, String>> post_res_list = JSONUtils.getListMapByJson(post_res);
                if (post_res_list.size()>0){
                    Map<String, String> map = post_res_list.get(0);
                    post_res_id = map.get("id");
                    post_res_content = map.get("content");
                    post_res_category = map.get("category");//1 图文 2 视频
                    if (TextUtils.equals("1",post_res_category)){
                        String post_res_pics = map.get("pics");
                        ArrayList<Map<String, String>> pics = JSONUtils.getListMapByJson(post_res_pics);
                        if (pics.size()>0){
                            Map<String, String> map1 = pics.get(0);
                            pic_right = map1.get("");
                        }
                    }else{
                        String post_res_video = map.get("video");
                        ArrayList<Map<String, String>> videos = JSONUtils.getListMapByJson(post_res_video);
                        if (videos.size()>0){
                            Map<String, String> map2 = videos.get(0);
                            videoW = map2.get("w");
                            videoH = map2.get("h");
                            String cover_img = map2.get("cover_img");
                            ArrayList<Map<String, String>> cover_imgs = JSONUtils.getListMapByJson(cover_img);
                            if (cover_imgs.size()>0){
                                Map<String, String> map1 = cover_imgs.get(0);
                                pic_right = map1.get("u");
                            }
                        }
                    }
                }
            }

            if (options != null) {
                Glide.with(mContext).load(a_avator).apply(options).into(ci_head_img);
            }else{
                Glide.with(mContext).load(a_avator).into(ci_head_img);
            }

            final String finalA_uid1 = a_uid;
            ci_head_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!TextUtils.equals("5",type)){
                        Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                        intent.putExtra("uid", finalA_uid1);
                        mContext.startActivity(intent);
                    }
                }
            });

            tv_nickname.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid", finalA_uid1);
                    mContext.startActivity(intent);
                }
            });

            tv_nickname.setText(a_nickname);
            tv_zan.setText(content);
            tv_ping.setText(reply_res_content);
            tv_time.setText(datetime);
            if (!TextUtils.isEmpty(pic_right)){
                tv_msg.setVisibility(View.GONE);
                iv_img.setVisibility(View.VISIBLE);
                Glide.with(mContext).load(pic_right).apply(options).into(iv_img);
            }else{
                tv_msg.setVisibility(View.VISIBLE);
                iv_img.setVisibility(View.GONE);
                tv_msg.setText(post_res_content);
            }
/**
 * * 消息类型：0评论我的帖子
 * 1评论我的评论
 * 2在我的帖子中回复了别人
 * 3赞了我的帖子
 * 4赞了我的评论
 * 5其它
 * 6系统可点击消息
 * 7对我的音频点赞
 */
            final String finalComment_res_id = comment_res_id;
            final String finalPost_res_id = post_res_id;
            final String finalComment_res_id1 = comment_res_id;
            final String finalComent_res_post_id = coment_res_post_id;
            final String finalComent_res_content = coment_res_content;
            final String finalA_sex = a_sex;
            final String finalA_avator = a_avator;
            final String finalA_nickname = a_nickname;
            final String finalA_uid = a_uid;
            final String finalComent_res_pics = coment_res_pics;
            final String finalPost_res_category = post_res_category;
            final String finalVideoH = videoH;
            final String finalVideoW = videoW;
            final String finalReply_res_id = reply_res_id;
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    if (TextUtils.equals("0",type)){
//                        VideoDetailsActivity.startVideoDetailsWithCommentDetailActivity
//                                (mContext,type, finalPost_res_id,item);
//                    }else if (TextUtils.equals("1",type)){
//                        VideoDetailsActivity.startVideoDetailsWithCommentDetailActivity
//                                (mContext,type,finalPost_res_id, item);
//                    }else if (TextUtils.equals("2",type)){
//
//                    }else if (TextUtils.equals("3",type)){
//                        VideoDetailsActivity.startVideoDetailsWithCommentDetailActivity
//                                (mContext,type, finalPost_res_id,item);
//                    }else if (TextUtils.equals("4",type)){
//                        VideoDetailsActivity.startVideoDetailsWithCommentDetailActivity
//                                (mContext,type,finalPost_res_id, item);
//                    }else if (TextUtils.equals("5",type)){
//
//                    }else if (TextUtils.equals("6",type)){
//
//                    }else{
//
//                    }

                    /**
                     * 0和3 4是留在详情页，1和跳到详情页之后再跳转到评论页面
                     */

                    if (type.equals("0") || type.equals("4")){
                        CDetailsListBean msgReplyListBean = new CDetailsListBean();
                        msgReplyListBean.setId(finalComment_res_id1);
                        msgReplyListBean.setPost_id(finalComent_res_post_id);
                        msgReplyListBean.setContent(finalComent_res_content);
                        msgReplyListBean.setLike_num("0");
                        msgReplyListBean.setIs_like(0);
                        msgReplyListBean.setReply_num("0");
                        msgReplyListBean.setDate(datetime);
                        UserBean userBeanX = new UserBean();
                        userBeanX.setSex(finalA_sex);
                        userBeanX.setAvator(finalA_avator);
                        userBeanX.setNickname(finalA_nickname);
                        userBeanX.setUid(finalA_uid);
                        msgReplyListBean.setUser(userBeanX);

                        List<RecommPictureBean> picsBeans = new ArrayList<>();
                        if (!TextUtils.isEmpty(finalComent_res_pics)) {
                            ArrayList<Map<String, String>> picss = JSONUtils.getListMapByJson(finalComent_res_pics);
                            for (int i = 0; i < picss.size(); i++) {
                                Map<String, String> o = picss.get(i);
                                String w = o.get("w");
                                String h = o.get("h");
                                String u = o.get("u");
                                boolean is_gif = Boolean.valueOf(o.get("is_gif"));

                                RecommPictureBean picsBean = new RecommPictureBean();
                                picsBean.setW(w);
                                picsBean.setH(h);
                                picsBean.setU(u);
                                picsBean.setIs_gif(is_gif);
                                picsBeans.add(picsBean);
                            }
                        }

                        msgReplyListBean.setPics(picsBeans);
                        intentType(finalPost_res_category,finalPost_res_id,item, finalVideoW, finalVideoH,finalComment_res_id, finalReply_res_id);
                    }else if (type.equals("1")) {
                        intentType(finalPost_res_category, finalPost_res_id, item, finalVideoW, finalVideoH,finalComment_res_id, finalReply_res_id);
                        //此处的延时操作，不管是否评论弹框，都是需要先打开详情页，如果需要评论弹框，延时两秒钟把评论弹起

//                        new android.os.Handler().postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//                                Intent intent = new Intent(mContext, CommentDetailAcitivity.class);
//                                intent.putExtra("post_id", finalPost_res_id);
//                                intent.putExtra("reply_id", finalComment_res_id);
//                                intent.putExtra("uid", uid);
//                                intent.putExtra("type", type);
//                                intent.putExtra("msg", (Serializable) item);
//                                mContext.startActivity(intent);
//                            }
//                        },2000);

                    }else if (type.equals("3")){
                        intentType(finalPost_res_category,finalPost_res_id,item, finalVideoW, finalVideoH,finalComment_res_id, finalReply_res_id);
                    }
                }
            });



            //这个应该是系统的推送链接，可点击的
//            String text = "你好哈哈哈哈哈哈哈哈哈哈或或或或或或或或或或或或或或或或或查看详情";
//            if (text.contains("查看详情")){
//                int i = text.indexOf("查看详情");
//                SpannableString spannableString = new SpannableString(text);
//                spannableString.setSpan(new ClickableSpan() {
//                    @Override
//                    public void updateDrawState(TextPaint ds) {
//                        ds.setColor(Color.parseColor("#7b2aff"));  //设置下划线颜色
//                        ds.setUnderlineText(true);  // 显示下划线
//                    }
//
//                    @Override
//                    public void onClick(View view) {     // TextView点击事件
//
//                    }
//
//                }, i, i+4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//                tv_ping.setText(spannableString);
//                tv_ping.setHighlightColor(mContext.getResources().getColor(android.R.color.transparent));
//                tv_ping.setMovementMethod(LinkMovementMethod.getInstance());
//
//            }else{
//                tv_ping.setText(text);
//            }
        }
    }


    /**
     * 首先2和1是判断视频还是图文，如果是视频判断是横向的还是竖向的
     * @param finalPost_res_category
     * @param finalPost_res_id
     */
    private void intentType(String finalPost_res_category, String finalPost_res_id,Map<String,String>item ,String w,String h,String comment_id,String reply_id){
        if (finalPost_res_category.equals("1")){
            VideoDetailsActivity.startVideoDetailsActivity(mContext,finalPost_res_id,VideoDetailsActivity.VIDEO_PICTURE,item,comment_id,reply_id);

        }else if (finalPost_res_category.equals("2")){
            if (Integer.parseInt(w) > Integer.parseInt(h)){
                VideoDetailsActivity.startVideoDetailsActivity(mContext,finalPost_res_id,VideoDetailsActivity.VIDEO_HORIZONTAL,item,comment_id,reply_id);
            }else{
                VideoDetailsActivity.startVideoDetailsActivity(mContext,finalPost_res_id,VideoDetailsActivity.VIDEO_VERTICAL,item,comment_id,reply_id);
            }
        }

    }












    public static class HashViewHolder extends RecyclerView.ViewHolder {

        private SparseArray<View> mViewCache = new SparseArray<View>();

        public HashViewHolder(View itemView) {
            super(itemView);
        }

        public void putView(int id) {
            if (itemView != null) {
                mViewCache.put(id, itemView.findViewById(id));
            }
        }

        public View findView(Integer id) {
            return mViewCache.get(id);
        }
    }

}
